package com.taoge.p4.common.redisMessageListener;


import com.taoge.p4.common.constants.RedisKeyConstant;
import com.taoge.p4.common.enums.RedisChannelEnum;
import com.taoge.p4.common.service.BrandService;
import com.taoge.p4.common.utils.RedisUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class BrandRefreshSubscribe implements MessageListener {

    @Resource
    private BrandService brandService;
    @Override
    public void onMessage(Message message, byte[] pattern) {
        log.info("收到消息：{}", message.toString());
        if(message.toString().equals(RedisKeyConstant.REFRESH)){
            log.info("品牌信息已更新，需要刷新缓存");
            brandService.removeCaffeine();
            RedisUtil.remove(RedisKeyConstant.TAOGE_BRAND_LIST);
            log.info("品牌信息已更新，缓存已刷新");
        }
    }
}
